import { utilities as csUtils, cache } from '@cornerstonejs/core';
import { getInformationOfImage } from './informationUtil';

const scalingPerImageId = {};
const imagePlaneModuleImageId = {};

function addInstance(imageId, scalingMetaData) {
	const imageURI = csUtils.imageIdToURI(imageId);
	scalingPerImageId[imageURI] = scalingMetaData;
}

function get(type, imageId) {

	if (type === 'imagePlaneModule') {
		let imagePlaneModule = imagePlaneModuleImageId[imageId];
		if (imagePlaneModule) {
			return imagePlaneModule;
		}
		const image = cache.getImage(imageId);
		if (!image) return;
		const { information } = getInformationOfImage(image);
		const { ImagerPixelSpacing, ImagePositionPatient } = information;
		if (!ImagerPixelSpacing) return;
		imagePlaneModule = { rowPixelSpacing: ImagerPixelSpacing[0], columnPixelSpacing: ImagerPixelSpacing[1], imagePositionPatient: ImagePositionPatient };
		imagePlaneModuleImageId[imageId] = imagePlaneModule;
		console.log('imagePlaneModule', imagePlaneModule)
		return imagePlaneModule;
	}
}

export default { addInstance, get };
